#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QToolBar>
#include <QToolButton>
#include <QDateTime>
#include <QTextEdit>
#include "sortingbox.h"
#include <sql.h>
#include <QTableWidget>
#include <QTcpSocket>
#include <QHostAddress>
#include <QProcess>
#include <QCloseEvent>
#include <QMenu>
#include <QMenuBar>
#include <QAction>
#include "msginf.h"
#include "exportdialog.h"
#include "importdialog.h"
#include <QTimer>

#ifdef __CURVE__
#include "qcustomplot.h"
#endif
class fsTcpSocket :public QTcpSocket
{
    Q_OBJECT
public:
    fsTcpSocket(QObject* parent=nullptr);
    virtual ~fsTcpSocket();
    void SetLocalPort(QString ip,quint16 port);
};

class MyWidget : public QWidget
{
public:
    QSize sizeHint() const
    {
        return QSize(300, 900); /* 在这里定义dock的初始大小 */
    }
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    SortingBox* m_box;
    CSql* m_SqLPara;
    QToolBar *toolBar;
    QToolButton *newRunButton;
    void closeEvent(QCloseEvent *event);
    void CreateMainBar();

    static void logOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg);
    static void write(QString str);
private:

    void CreateToolBar();
    QAction* ActToolbar[3];
    QTableWidget* m_RunTable;
    QDockWidget *dock1;
    QDockWidget *dock2;
    void addItem(QString str,QString layer);
    fsTcpSocket* m_TcpRobot;
    fsTcpSocket* m_TcpCamera;
    fsTcpSocket* m_TcpMIS;
    int showItem(int row,QStringList ls);
    int getGapFlushFlag(QString Measure,QString sgap,QString sflush);
    void test();

    QProcess  *m_Process;

    QString m_OpenProjectName;
    //
    int m_MisConReplayCnt;


#ifdef __CURVE__
    QCustomPlot *myPlot;
#endif
    QString m_clsid;
    void onSaveData(QString point,QString gap,QString flush,int flag);
    //
    QLineEdit *m_ModeTxt;

    QAction *m_RunAct;
    QAction *m_OpenSolutionAct;
    QAction *m_MeasureAct;
    QAction *m_SettingAct;
    QAction *m_helpAct;
    QAction *m_aboutAct;
    QAction *m_exportAct;
    QAction *m_importAct;
signals:
    void myRunSignal(bool); //定义信号（信号全部是公有的）
    void boxShowPin(QString strPic,QString strPin);
    void showGapFlush(QString pin,QString gap,QString flush,int flag);

private slots:
    void myRunning();
    void mySetting();
    void myPointS();
    void showRunTable();
    bool showRunTableAuto(QString Prj);
    void myHelp();
    void myAbout();
    void myExport();
    void myImport();

    void onConnectCamera();
    void onConnectMIS();
    void onConnectRobot();
    void onDisconnectCamera();
    void onDisconnectRobot();
    void onDisconnectMIS();
    void onReadyReadCamera();
    void onReadyReadRobot();
    void onReadyReadMIS();

    void displayError(QAbstractSocket::SocketError);
    void RuncellChanged(int row,int col);
    void RunitemChanged(QTableWidgetItem* item);
    void RunitemSelectionChanged();

    void dogonOutput();
    void OnClearRunTable();
    void OnShowHideDock1(bool bf);
    void OnMISReplay();

};
#endif // MAINWINDOW_H
